<template>
    <el-container class="logo">
        <el-main>
            <el-form :rules="rules" class="login-container" label-position="left" :model="loginForm" label-width="0px" v-loading="loading">
                <h3 class="login_title">系统登录</h3>
                <el-form-item prop="username">
                    <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
                </el-form-item>
                <el-form-item prop="rememberMe">
                    <el-row>
                        <el-col :span="6">
                            <router-link to="/resetPass">忘记密码</router-link>
                        </el-col>
                        <el-col :span="6" :offset="12">
                            <router-link to="/register">新用户?注册</router-link>
                        </el-col>
                    </el-row>

                    <el-checkbox v-model="loginForm.rememberMe" style="margin-left: 80%" class="login_remember">记住我</el-checkbox>
                    <el-button type="primary" style="width: 100%" @click="login">登录</el-button>
                </el-form-item>
            </el-form>
        </el-main>
    </el-container>
</template>
<script>
	export default {
        data(){
            return {
                rules: {
                    username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
                    password: [{required: true, message: '请输入密码', trigger: 'blur'}]
                },
                loginForm: {
                    username: 'zsk',
                    password: '123456',
                    rememberMe: ''
                },
                loading: false
            }
        },
        methods:{
            login(){
                const _this = this;
                this.loading=true;
                this.postRequest(
                    '/login',
                    {
                        'username':this.loginForm.username,
                        'password':this.loginForm.password,
                        'rememberMe':this.loginForm.rememberMe
                    }
                )
                    .then(function (resp) {
                        _this.loading=false;
                        if (resp && resp.data && resp.data.code === '200') {
                            const data = resp.data;
                            _this.$store.commit('login',data.result);
                            console.log(data.result);
                            _this.$router.push('/')
                        }
                        console.log(resp && resp.data && resp.data.code === '200');
                    });
            }
        }
    }
</script>
<style  scoped>
    .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }
  .login_remember {
    margin: 0px 0px 35px 0px;
    text-align: left;
  }
    .logo{
        background-size: 100% 100%;
        background-repeat: no-repeat;
        background-image: url("../assets/logo.png");
    }
</style>